﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TGB.Core.Infrastructure;
using TGBTech.Web.Models;

namespace TGBTech.Web.Controllers
{
    public class TestController : Controller
    {
        private TGBTechDb db = new TGBTechDb();
        //
        // GET: /Test/
        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Test/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Test/Create
        public ActionResult Create()
        {
            var list = db.TaiKhoan.Where(p => p.State == true).ToList();
            return View(list);
        }

        //
        // POST: /Test/Create
        [HttpPost]
        public String Create(Test model)
        {
                // TODO: Add insert logic here
                if (ReferenceEquals(model.Id, null))
                    model.Id = 0;

                if (ReferenceEquals(model.Name, null))
                    model.Name = String.Empty;

                return "ok";
        }

        //
        // GET: /Test/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Test/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Test/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Test/Delete/5
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
